<?php

class UrlHelper {
	function href_seo( $controller, $seo = '', $ext='.24h') {
		global $URL_MAP;
		$count = 0;
		foreach( $URL_MAP as $url=>$map) {
			$controller = str_replace( $map, $url.'/', $controller, $count);
			if( $count>0)  break;
		}
		$controller=preg_replace( '#\-$#', '', str_replace( '/', '-', $controller));
		$seo = str_replace( '_', '-', _url_text( $seo, ''));
		return $this->base_url.$seo.'_'.$controller.$ext;
	}

	function href( $link, $show=true, $back=false) {
		$link = $this->base_url.$link;
		if( $back) {
			$uri = preg_replace( '#back\=[^&]+#', '', $_SERVER['REQUEST_URI']);
			if( !preg_match( '#\?#', $link)) {
				$link .= '?back='.fw24h_base64_url_encode( $uri);
			}else{
				$link .= '&back='.fw24h_base64_url_encode( $uri);
			}
		}
		if( $show) {
			echo $link;
		}
		return $link;
	}
 	
 	function index_page() {
		global $_FW24H_CONFIG_;
		return $_FW24H_CONFIG_['default_controller'].'/'.$_FW24H_CONFIG_['default_action'];
	}

	function base_url() {
		return BASE_URL;
	}

	function site_url( $url) {
		return BASE_URL.'/'.$url;
	}

	function img_src( $image) {
		return IMAGE_URL.$image;
	}
}
 
